<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://static.web.sdo.com/chuanshi/common/18.2.0/react.development.js"></script>
    <script src="https://static.web.sdo.com/chuanshi/common/18.2.0/react-dom.development.js"></script>
    <script src="https://static.web.sdo.com/chuanshi/common/18.2.0/babel.min.js"></script>
</head>
<body>
    <div id="app"></div>
</body>
</html>
<script type="text/babel">
    class App extends React.Component {
        state = { num: 0 }
        getSnapshotBeforeUpdate() {
            console.log("========getSnapshotBeforeUpdate========")
            return { myname: "cowen" };
        }
        componentDidUpdate(prevProps, prevState, snapValue) {
            console.log(prevProps, prevState, snapValue)
            console.log("========componentDidUpdate========")
        }
        increment = () => {
            this.setState({
                num: this.state.num + 1
            })
        }
        render() {
            return (
                <div className="container">
                    <div className="mt-4 alert alert-dark">
                        当前数值为：{this.state.num}
                    </div>
                    <button onClick={this.increment} className="btn btn-outline-danger">增加</button>
                </div>
            )
        }
    }
    ReactDOM.createRoot(document.getElementById("app")).render(<App name="app" />)
</script>